import java.util.Scanner;

public class Text1 {
    public static int func (int n){
        int tmp = n;
        int x = 0;
        int ret = 0;

        while(tmp>=3){
            int cur = tmp;
            tmp=tmp/3;
            ret+=tmp;
            x = cur - 3*tmp;
            tmp+=x;
        }
        if (tmp==2){
            ret++;
        }

        return ret;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = 0;
        int ret = 0;
        do {
            n= sc.nextInt();
            ret = func(n);
            if (n!=0)
            System.out.println(ret);
        } while(n!=0);
    }
}
